var app = getApp();
Page( Object.assign({},{
    data:{
        article : {},
        sortname : '',
        sortid : 0,
        content : '',
        gid : 0,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        var id = options.id ? options.id : '';

        self.setData({
            gid : options.gid > 0 ? options.gid : 0,
        })
        app.com.http('quest','POST',{op:'pubinfo'},0,false,'','',function(res){
            if (!res.data.errno && res.data) {
                self.setData({
                    sort : res.data.data.sort,
                    params : res.data.data.params,
                    sharedata : res.data.data.sharedata,
                    inited : true,
                });
            }else{
                app.com.alert(res.data.message,function(){
                    app.com.backPage();
                });
            }
        });
        wx.setNavigationBarTitle({
            title:  '发布',
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: '',
            path: '',
        }
    },
    setsort(e){
        this.setData({
            sortname : this.data.sort[e.detail.value].name,
            sortid : this.data.sort[e.detail.value].id,
        })
    },
    onPullDownRefresh: function () {
        var self = this;
        app.com.confirm('是否要清空内容？',function(){
            self.setData({
                content : '',
                sortname : '',
                sortid : 0,
            })
        },false,'取消','清空');
    },
    contentfn(e){
        this.setData({
            content : e.detail.value
        })
    },
    pub(){
        var self = this;
        var postdata = {
            op : 'add',
            sortid : self.data.sortid,
            gid : self.data.gid,
            content : self.data.content,
        };
        app.com.http('quest','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data) {
                app.com.alert(res.data.message,function(){
                    var pages = getCurrentPages();
                    var beforePage = pages[pages.length - 2];
                    beforePage.onPullDownRefresh();
                    app.com.backPage(0);
                });
            }else{
                app.com.alert(res.data.message);
            }
        });
        self.subMess();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e);
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    weburl : function(e){
        app.com.toweburl( e,this );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    FormIdsubmit : function(e){
        if( app.globalData.formarr.length <= 50 ) app.globalData.formarr.push(e.detail.formId);
    },
    subMess(){
        var self = this;
        wx.requestSubscribeMessage({
            tmplIds : self.data.params.submess,
            complete : function(){}
        })        
    }


}))